package com.xufeng.demo.Controller;

import cn.springmix.base.lang.entity.R;
import cn.springmix.base.lang.exception.BaseException;
import cn.springmix.base.lang.exception.Exceptions;
import cn.springmix.base.lang.exception.GlobalCodeEnum;
import cn.springmix.core.annotation.NotAutoResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.concurrent.Callable;


/**
 * @author xufeng
 * @description: 测试一下包装类 和全局异常
 * @date 2022-04-20 13:47
 */
@Slf4j
@RestController
@RequestMapping
@Validated
public class TestController {

    /**
     * 测试国际化异常
     *
     * @return
     */
    @GetMapping("/test")
    @NotAutoResult
    public R hello() {
       // Exceptions.msg("error.param.format", String.valueOf(1000));
        Exceptions.throwEx(BaseException.class, GlobalCodeEnum.GL_FAIL_9995);
        return R.OK("hello");
    }

    @GetMapping("/test1")
    @NotAutoResult
    public R hello(@NotNull(message = "{error.param.format}") String id) {
        //Exceptions.msg("error.param.format");
        return R.OK("hello");
    }

    /**
     * 异步返回 取决于线程池和队列。线程有开销。涉及高耗时接口适合使用。测试单机4300并发。可能是线程开销太大
     *
     * @return
     */
    @GetMapping("/callableAsync")
    @NotAutoResult
    public Callable<R> callableAsync() {
        return () -> R.OK("hello");
    }

    /**
     * 测试tomcat调优单机4w并发
     * @return
     */
    @GetMapping("/callable")
    @NotAutoResult
    public Object hello1() {
        return "hello";
    }
}
